<template>
	<view>
		<view class="image"><image src="../../static/img/tao.webp"></image></view>
		<view class="phone">账号注册</view>
			<view class="u-demo-block__content">
						<u-input type="number" v-model="phone" maxlength=11 placeholder="请输入手机号" color="red" border="bottom"  clearable>
							<u--text
								text="账号"
								slot="prefix"
								type="tips"
							></u--text>
						</u-input>	
						<u-input type="password" class="pass" v-model="password" placeholder="请输入密码" color="red" border="bottom"  clearable>
							<u--text
								text="密码"
								slot="prefix"
								type="tips"
							></u--text>
						</u-input>	
						<u-input type="password" class="pass" v-model="repassword" placeholder="请再输入密码" color="red" border="bottom"  clearable>
							<u--text
								text="密码"
								slot="prefix"
								type="tips"
							></u--text>
						</u-input>	
						<u-button @click="zhuce()" class="button" type="error" text="立即注册"></u-button>
					</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:'',
				password:'',
				repassword:''
			}
		},
		methods: {
			zhuce(){
				if(this.phone==''){	
					uni.showToast({
						title:'请输入手机号',
						icon:'none',
						duration:2000
					})
				}
				else if(this.phone.length!=11){
					uni.showToast({
						title:'请输入正确的手机号',
						icon:'none',
						duration:2000
					})
				}else if(this.password==''||this.repassword==''){
					uni.showToast({
						title:'请输入密码',
						icon:'none',
						duration:2000
					})
				}else if(this.password!=this.repassword){
					uni.showToast({
						title:'密码前后不一致，请重新输入',
						icon:'none',
						duration:2000
					})
				}else{
					uni.request({
						url:'www.movie.com/api/movie_mysql/zhuce.php',
						method:'GET',
						data:{
							phone:this.phone,
							password:this.password
						},
						success: (res) => {
							
							console.log(res.data)
							if(res.data=="注册失败"){
									uni.showToast({
										title:'该手机号已存在，注册失败',
										icon:'none',
										duration:2000
									})
							}else{
								if(res.statusCode==200){
									uni.showToast({
										title:'注册成功',
										duration:2000,
										mask:true
									})
									setTimeout(function(){
										uni.navigateBack({})
									},2000)
								}else{
									uni.showToast({
										title:'注册失败',
										icon:'none',
										duration:2000
									})
								}
							}
						}
					})
				}
			},
		}
	}
</script>

<style>
.image{
	width:100px;
	height:70px;
	margin:0 auto;
	margin-top:30px;
}
.image image{
	width:100%;
	height:100%;
}
.phone{
font-size: 20px;
text-align: center;
color:rgb(253,104,123);
margin-top:10px;
}
.u-demo-block__content{
	width:80%;
	margin:0 auto;
	margin-top:10px;
}
.pass{
	margin-top:20px;
}
.button{
	margin-top:20px;
}
.no{
	text-align: center;
	margin-top:10px;
}
.zhuce{
	color:rgb(245,108,108);
	text-align: center;
}
</style>
